<?php

namespace app\index\dao;

use app\common\model\LawyerImpression;
use ShidianUtil\Thinkphp\Dao\DaoTrait;
use ShidianUtil\Thinkphp\Lib\Logger\RequestLogger;

/**
 * LawyerImpressionDao 数据访问对象
 * Class LawyerImpressionDao
 * @package app\index\dao
 * @method LawyerImpression findByPK(?int $id, $field = true)
 * @method \think\Collection selectAll(?int $page, ?int $page_size, $field = true)
 * @method LawyerImpression insertActive(array $params, array $allow_field = [])
 * @method LawyerImpression updateActive(LawyerImpression $model, array $params, array $allow_field = [])
 * @method LawyerImpression findAndUpdateActive(int $id, array $params, array $allow_field = [])
 * @method LawyerImpression updateActiveByClosure(\Closure $closure, array $params, array $allow_field = [])
 * @method void deleteModel(LawyerImpression $model)
 * @method void deleteById(int|array|\Closure $id, bool $force = false)
 * @link https://www.kancloud.cn/manual/thinkphp6_0/1037579
 * @link https://www.kancloud.cn/manual/think-orm/1257998
 * @link https://www.kancloud.cn/thinkphp/master-database-and-model/265551
 */
class LawyerImpressionDao
{
    use DaoTrait;

    /**
     * @var LawyerImpression
     */
    private $baseModel;

    /**
     * LawyerImpressionDao constructor.
     */
    public function __construct()
    {
        $this->baseModel = LawyerImpression::class;
    }

    /**
     * 记录曝光行为
     * @param $scene
     * @param $lawyerId
     * @param $memberId
     * @return void
     */
    public function insert($scene, $lawyerId, $memberId): void
    {
        // 渠道链路
        ['pf' => $pf, 'chain' => $chain, 'promotionGroupId' => $promotionGroupId] = getChainParams();

        // 请求记录
        $request = RequestLogger::get();
        $requestId = 0;
        if ($request) {
            $requestId = $request->id;
        }

        $data = [
            'scene' => $scene,
            'lawyerId' => $lawyerId,
            'memberId' => $memberId,
            'requestId' => $requestId,
            'pf' => $pf,
            'chain' => $chain,
            'promotionGroupId' => $promotionGroupId,
        ];

        $this->insertActive($data);
    }
}
